<template>
  <div class="body">
    <div>
      <img class="logo" src="../../assets/images/logo.png" />
    </div>
    <div class="box flex items-center justify-between p-2rem">
      <div class="flex items-center">
        <img class="w-4.4rem h-4.4em m-r-1.3rem" src="../../assets/images/my/user.png" />
        <div class="font-size-1.8rem">{{ store.tgUser?.first_name }}</div>
      </div>
      <img @click="go('/invite')" class="w-2.7rem h-2.7rem" src="../../assets/images/my/code.png" />
    </div>

    <div class="box p-x-3rem p-y-2rem flex justify-between">
      <!-- <div class="fx-c act" @click="go('/assets?type=2')">
        <div>{{ $t('home.my.credit') }}</div>
        <div class="num">{{ assets?.point }}</div>
      </div> -->
      <div class="fx-c act" @click="go('/coupons')">
        <div>{{ $t('home.my.coupon') }}</div>
        <div class="num">{{ assets?.coupon }}</div>
      </div>
      <div class="fx-c act" @click="go('/assets?type=1')">
        <div>{{ $t('home.home.balance') }}</div>
        <div class="num">{{ assets?.balance }}</div>
      </div>
      <div class="fx-c act" @click="go('/assets?type=1')">
        <div>{{ $t('home.home.cash') }}</div>
        <div class="num">{{ assets?.cash }}</div>
      </div>
    </div>

    <div v-if="isEmployee" style="margin: 2rem">
      <van-button type="primary" block round @click="go('/clockIn')">
        {{ $t('clock.clockIn') }}
      </van-button>
    </div>

    <div class="box p-2rem">
      <div class="msg-title" @click="go('/msgs')">{{ $t('home.my.msgs') }}</div>
      <div>
        <div class="msg" v-for="item in msgs" :key="item.id">
          <p>{{ item.createTime }}</p>
          <div>{{ item.content }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const store = useAppStore()

const router = useRouter()

const assets = ref<ApiAssetVO>()
const msgs = ref<ApiUserMsg[]>()

const isEmployee = ref(false)

function go(path: string) {
  router.push(path)
}

onMounted(() => {
  getAsset()
  getMsg()
  getEmployee()
})

onActivated(() => getAsset())

async function getAsset() {
  assets.value = await apis.api.userAssetAsset()
}

async function getMsg() {
  const msgData = await apis.api.userAssetMsgs({ page: 1 })
  msgs.value = msgData.lists
}

async function getEmployee() {
  const employee = await apis.api.userEmployeeIsEmployee()
  if (employee && employee.id) {
    isEmployee.value = true
    localStorage.setItem('employeeId', employee.id + '')
    localStorage.setItem('employeeOpenId', employee.openid!)
  }
}
</script>

<style lang="scss" scoped>
.body {
  overflow: hidden;
  width: 100%;
  min-height: 100vh;
  background-image: url('../../assets/images/my/bg.png');
  background-repeat: no-repeat;
  background-size: 100% 21.1rem;
  background-color: #f6f6f6;
}
.logo {
  width: 8.9rem;
  height: 10.6rem;
  display: block;
  margin: 4.5rem auto 20px;
}
.box {
  border-radius: 1.2rem;
  background-color: #fff;
  margin: 0 1.25rem 1.5rem;
}
.act {
  font-size: 1.4rem;
  .num {
    margin-top: 0.7rem;
  }
}

.msg {
  margin-top: 10px;
  border-radius: 1rem 1rem 1rem 0.2rem;
  color: #333333;
  font-size: 1.2rem;
  background-color: #f6f6f6;
  padding: 6px 10px;
  p {
    margin: 0 0 4px 0;
    color: #999999;
    font-size: 1rem;
  }
}
.msg-title {
  color: #3aa1a2;
  font-size: 1.6rem;
  text-align: center;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}
</style>
